// Town 1: Lost Bahssikava
begintownscript;

variables;

short dummy;
string dlgstr;

body;

beginstate INIT_STATE;
// This is where names go
set_name(6,"Skassa");
set_name(15,"Phaedra");
set_char_dialogue_pic(15,535,0);
set_name(16,"Machrone");
set_name(18,"Kass");
set_char_dialogue_pic(18,533,0);
set_name(19,"Gatekeeper");
set_crime_tolerance(2);
set_name(39,"Huge mutant lizard");
set_level(39,50);

if ((get_flag(4,0) != 1) && (get_flag(4,1) != 1))
	end();
	
	set_flag(1,12,1);
	if (get_flag(4,0) == 1)
		{relocate_character(0,13,8);
		relocate_character(1,13,9);
		relocate_character(2,12,9);
		relocate_character(3,11,9);
		set_character_facing(0,0);
		set_character_facing(1,6);
		set_character_facing(2,6);
		set_character_facing(3,6);
		force_view_center(13,8);
		set_flag(4,0,2);
		set_flag(1,8,2);
		force_instant_terrain_redraw();
		}

	if (get_flag(4,1) == 1)
		{relocate_character(0,13,10);
		relocate_character(1,13,9);
		relocate_character(2,12,9);
		relocate_character(3,11,9);
		set_character_facing(0,4);
		set_character_facing(1,6);
		set_character_facing(2,6);
		set_character_facing(3,6);
		force_view_center(13,10);
		set_flag(4,1,2);
		set_flag(1,8,2);
		force_instant_terrain_redraw();
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
// This is where text bubbles go
break;

beginstate 10;
	move_to_new_town(2,36,45);
break;

beginstate 11;
	if (get_flag(1,0) == 1)
	end();
	else
	{message_dialog("The view from these windows is incredible. You can see the waterfalls from the inside.","The water comes from a hole in the cave ceiling that you could see from the other side. It falls right in front of the windows to the lake below. Here you can see it up close.");
	set_flag(1,0,1); }
break;

beginstate 12;
	if (get_flag(1,1) == 1)
	end();
	else
	{message_dialog("Curious. The hallway here has windows into guardrooms. These guards could attack anyone coming through here. Also, the hallway is extremely narrow, so that not many people could come through at once.","");
	set_flag(1,1,1); }
break;

beginstate 13;
	if (get_flag(1,2) == 1)
	end();
	else
	{message_dialog("You enter Bahssikava. Somewhere within, Legare waits. He should be able to tell you your misson.","As you take your first few steps, you notice that the nearby area has many very old bloodstains. Someone has tried to clean them, but they are still visible.");
	set_flag(1,2,1); }
break;

beginstate 14;
	if (get_flag(1,3) == 1)
	end();
	else
	{message_dialog("Many slith corpses have been shoved in this back tunnel. The Empire's symbol was painted on the wall.","The bodies are old, probably at least ten or fifteen years.");
	set_flag(1,3,1); }
break;

beginstate 15;
	if (get_flag(1,4) == 1)
	end();
	else
	{reset_dialog();
	add_dialog_str(0,"The runes here glow viciously. This looks as though it used to be a pair of breeding pools where baby sliths were raised. The pools have since been filled with lava.",0);
	add_dialog_str(1,"Apparently destroying this place was not enough. The Empire wanted to make sure that it could never be a viable slith town again, an effort that is not without irony since it is now the central rallying point for these sliths.",0);
	add_dialog_str(2,"The room is filled with demonic energy, choking you. Garzahd, leader of the Empire's forces during the Empire-Averum War, was not above using dark powers to augment his spells.",0);
	run_dialog(1);
	set_flag(1,4,1); }
break;

beginstate 16;
	if (get_flag(1,5) == 1)
	end();
	
	clear_buffer();
	append_string("A very calm, serene slith priestess turns to face you as you come in. ");
	if (get_flag(250,0) >= 4) // party contains sliths
		{append_string("She smiles to see ");
		if (get_flag(251,3) == 1) // number of sliths in party is 1
			append_string("a fellow slith,");
		else
			append_string("fellow sliths,");
		append_string(" and then ");
		}
	else
		{append_string("She frowns when she notices that you are ");
		if (get_flag(250,0) == 1)
			{if (party_size() > 1)
				append_string("all humans,");
			else
				append_string("a human,");
			}
		if (get_flag(250,0) == 2)
			{if (party_size() > 1)
				append_string("all nephils,");
			else
				append_string("a nephil,");
			}
		if (get_flag(250,0) == 3)
			append_string("not sliths,");
		append_string(" but nevertheless,");
		}
	append_string("she continues going on about her work");
	if (get_flag(250,0) == 4)
		append_string(".");
	else
		append_string(" not bothered overmuch by your presence.");
	get_buffer_text(dlgstr);
	message_dialog("This room is more cleaned up than the others. It still has old bloodstains, but they are faint. The central feature of the room is the altar.",dlgstr);
	set_flag(1,5,1);
break;

beginstate 17;
	if (get_flag(1,18) == 1)
		end();
	else
		{message_dialog("In this room sits a young man scribbling down notes. He looks up at you. _Ah! Adventurers!_ he says. He says the word, _Adventurers,_ differently than most say it.","Most say it the way that one would say, _A chitrach infestation!_ or _A steaming mound of filth on my favorite chair!_ This person actually sounded happy to see you.");
		set_flag(1,18,1); }
break;

beginstate 18;
	if (get_flag(1,8) != 0)
	{end(); }
	else
	{message_dialog("As you enter this room, you see Kass! _Hello,_ he says, smiling. His tone is a little strained, however. Something must be wrong.","");
	set_flag(1,8,1);
	begin_talk_mode(31); }
break;

beginstate 19;
	block_entry(1);
	message_dialog("Kass raises a hand to stop you before you approach this door. _I'm sorry,_ he says, _but the Prophet isn't seeing any visitors at the moment. You'll have to come back later.","");
break;

beginstate 20;
	message_dialog("The gatekeeper says firmly, _Don't touch that!_ You take your hand away.","");
break;

beginstate 21;
	if (get_flag(1,10) == 0)
		block_entry(1);
break;

beginstate 22;
	if (get_flag(1,11) == 1)
		{block_entry(1);
		message_dialog("Kass is waiting for you to enter the room so that he can tell you the story. You can't leave.","");
		}
break;

beginstate 23;
	if (get_flag(1,11) != 1)
		end();
	
	if (get_flag(250,9)) {
		reset_dialog();
		add_dialog_str(0,"A cut scene is coming up in which Kass narrates the history of the sliths and the significance of your quest within that history. Would you like to skip it or see it?",0);
		add_dialog_choice(0,"Skip it.");
		add_dialog_choice(1,"See it.");
		if (run_dialog(1) == 1)
			set_state_continue(31);
		}
		
	message_dialog("Kass begins speaking, and his voice sweeps you away...","");
	move_to_new_town(4,60,4);
break;

beginstate 24;
	if (get_flag(1,15) == 1)
	end();
	else
	{message_dialog("You step out to a ledge extending out over a large pit. The air is very warm, and you can hear loud hissing coming from below.","");
	set_flag(1,15,1); }
break;

beginstate 25;
	if ((get_flag(1,16) == 1) || (is_combat() == 1))
	end();
	else
	{message_dialog("Now that you have a little time to look around, you look off the edge of the pit. You can't see to the bottom, but you can smell something.","The drakes must have been able to fly down from those ledges and hunt food somewhere below. Perhaps that means that the monsters underneath this level will be drake food, and easier to fight.");
	set_flag(1,16,1); }
break;

beginstate 26;
	if (get_flag(1,17) == 1)
	end();
	else
	{message_dialog("How odd. This cave has the same Empire markings that covered the ruins around the entrance to Bahssikava. Apparently when Empire soldiers came ravaging through here, they did not stop when they killed all the sliths in the village.","There was a cave-in here recently.");
	set_flag(1,17,1); }
break;

beginstate 27;
	message_dialog("This is the body of an Empire soldier. He has been stripped of all of his valuables, including his sword and his armor.","");
break;

beginstate 28;
if ((get_flag(3,0) == 1) && (get_flag(3,2) == 1))
	{message_dialog("Just as you are beginning to become alarmed at the sounds you are hearing, Kass appears in front of you. He speaks very rapidly.","");

	if (get_flag(250,9)) {
		reset_dialog();
		add_dialog_str(0,"You have reached another cut scene, one in which Kass describes the current attack on Bahssikava and why it's happening. Would you like to skip it or see it?",0);
		add_dialog_choice(0,"Skip it.");
		add_dialog_choice(1,"See it.");
		if (run_dialog(1) == 1)
			set_state_continue(32);
		}
		
	place_monster(15,11,36,0);
	set_character_facing(86,6);
	text_bubble_on_char(86,"There you are!");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));

	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"We are under attack.");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));

	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"Come with me.");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));

	text_bubble_on_char(86,"");
	text_bubble_on_char(86,"I will explain as we walk.");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));

	move_to_new_town(5,58,28); }
break;

beginstate 29;
	if ((get_flag(1,21) == 0) && ((get_flag(3,0) == 1) && (get_flag(3,2) == 1)))
	{message_dialog("As you draw close to Bahssikava, you hear some commotion. Something is wrong.","As you listen carefully, you can distinguish for certain that it is the sound of fighting. There is a massive battle raging in Bahssikava right now.");
	set_flag(1,21,1); }
break;

beginstate 30;
	if (get_flag(1,20) == 1)
	end();
	else
	{message_dialog("There was a cave-in here. The dirt still covers the entire area, and the pieces of the roof and wall that came down are all around, too. You can't pass.","");
	set_flag(1,20,1); }
break;

beginstate 31;
	reset_dialog();
	add_dialog_str(0,"Kass describes the history of the sliths. Essentially, Avernite sliths are descended from exiles from the slith homeland from two hundred years ago, and many of them were Darklings who worshipped a demon lord named Grah-Hoth.",0);
	add_dialog_str(1,"Some sliths broke away from the Darklings and founded Bahssikava. Legare, a Bahssikavan, spent twenty years in the tunnels underneath Bahssikava, and eventually he emerged as prophet to begin this expedition.",0);
	add_dialog_str(2,"The way back to the slith homeland is through the tunnels below here, and Legare wants you to clear those tunnels of the monsters currently inhabiting it.",0);
	set_flag(1,8,1 + run_dialog(1));
	set_flag(1,11,2);
	set_flag(1,12,1);
	toggle_quest(0,0);
	toggle_quest(1,1);
break;

beginstate 32;
	reset_dialog();
	add_dialog_str(0,"Kass leads you on a hurried walk through Bahssikava, showing you a secret passage in one room at leads to a tunnel you've never seen. As you follow him, he explains what's going on.",0);
	add_dialog_str(1,"When Legare preached in Gnass, he made a number of enemies, including the established priesthood, and they exiled him. Now they have come for him and have attacked him and his followers.",0);
	add_dialog_str(2,"Your responsiblity remains the same: reach the steel doors. However, you will not be able to go back up to the outdoors anymore.",0);
	add_dialog_str(3,"Once he has finished saying all this, Kass leaves you in a new part of Bahssikava, departing with the words, _Good luck._",0);
	set_flag(5,0,1 + run_dialog(1));
	move_to_new_town(2,3,35);
break;